<?php include ("inc/db_config.inc"); ?>
<?php
if (isset($_REQUEST['cid'])) {
	$cid=$_REQUEST['cid'];
    $result_cata = mysql_query("select * from type where id=$cid");
    $row_cata = mysql_fetch_array($result_cata);
    $g_title = $row_cata['name'];
}
?>
<?php

$g_tab = "catalog";

function utf_substr($str, $len)
{
    for ($i = 0; $i < $len; $i++) {
        $temp_str = substr($str, 0, 1);
        if (ord($temp_str) > 127) {
            $i++;
            if ($i < $len) {
                $new_str[] = substr($str, 0, 3);
                $str = substr($str, 3);
            }
        } else {
            $new_str[] = substr($str, 0, 1);
            $str = substr($str, 1);
        }
    }
    return join($new_str);
}
?>
        <?php include ("header.php"); ?>
<div class="crumb"><a href="index.php">首页</a>&gt;分类</div>
			<div class="main">
				<div class="container l">
					<div class="conbox">
						<div class="cb_hd">
							<span class="cb_tl"></span>
							<span class="cb_tr"></span>
							<h2>文章分类</h2>
						</div>
						<div class="cb_bd">
                        
							<div class="list_result">
								<strong><?php echo $row_cata['name']; ?></strong>分类下面的文章:
							</div>
<?php
function getPageInfo($sql, $ps, $currPage)
{
    global $beginNum, $begin, $end, $page, $totalpage;
    //分页开始
    $result = mysql_query($sql);
    //$all=mysql_fetch_array($rn);
    //$total=$all[0];//全部记录数目
    $total = mysql_num_rows($result);
    $pagesize = $ps;
    $page = $currPage;
    $totalpage = ceil($total / $pagesize);
    if ($page < 1) {
        $page = 1;
    }
    if ($page > $totalpage) {
        $page = $totalpage;
    }
    $begin = $page - 4;
    $end = $page + 5;
    if ($page < 5) {
        $begin = 1;
        $end = 10;
    }
    if ($page > $totalpage - 5) {
        $begin = $totalpage - 9;
        $end = $totalpage;
    }
    if ($begin < 1) {
        $begin = 1;
    }
    if ($end > $totalpage) {
        $end = $totalpage;
    }
    $beginNum = ($page - 1) * $pagesize;


    //分页结束
}
if (isset($_REQUEST['p']) && $_REQUEST['p'] != "") {
    $currPage = $_REQUEST['p'];
} else {
    $currPage = 1;
}
$pagesize = 10;
getPageInfo("select * from info where type='$cid'", $pagesize, $currPage);


//分页开始
/*
$sn="select count(*) from info where type='$cid' order by id desc";
$rn=mysql_query($sn);
$all=mysql_fetch_array($rn);
$total=$all[0];//全部记录数目
$pagesize=10;
if(!empty($_GET['p'])){
$page=$_GET['p'];
}else{
$page=1;
}
$totalpage=ceil($total/$pagesize);
if($page<1){
$page=1;
}   
if($page>$totalpage){
$page=$totalpage;
}
$begin=$page-4;
$end=$page+5;
if($page<5){
$begin=1;
$end=10;
}
if($page>$totalpage-5){
$begin=$totalpage-9;
$end=$totalpage;
}
if($begin<1){
$begin=1;
}
if($end>$totalpage){
$end=$totalpage;
}
$beginNum=($page-1)*$pagesize;
*/

//分页结束

?>
                            <?php

$result_list = mysql_query("select * from info where type ='$cid' order by id desc limit $beginNum,$pagesize");
if (mysql_affected_rows() > 0) {
    while ($row_list = mysql_fetch_array($result_list)) {
?>
							<div class="post">
								<h3><a href="show.php?pid=<?php echo $row_list['id']; ?>"><?php echo $row_list['title']; ?></a></h3>
								<span class="date"><?php echo $row_list['created']; ?></span>
								<p><?php echo utf_substr(strip_tags($row_list['content']), 200); ?>...</p>
								<div class="post_meta">
									<a href="#">评论(0)</a>|浏览(37)
								</div>
							</div>
                            <?php }
} else { ?>
                                <div class="post">
                                  此分类下暂无文章!
                                </div>
                            <?php } ?>
							
							
						</div>
						<div class="cb_ft"></div>
					</div>
<?php if ($totalpage > 1) { ?>
					<div class="pageinfo">
								<a href="?cid=<?php echo $cid; ?>&p=<?php echo $page - 1; ?>">上一页</a>
                                <?php
    for ($i = $begin; $i <= $end; $i++) {
        if ($i == $page) {
            echo "&nbsp;<span>" . $i . "</span>";
        } else {
            echo "&nbsp;<a href='?cid=$cid&p=$i'>" . $i . "</a>";
        }
    }
?>
								
								<a href="?cid=<?php echo $cid; ?>&p=<?php echo $page + 1; ?>">下一页</a>
							</div>
                            <?php } ?>
				</div>
				<?php include ("sidebar.php"); ?>
				<div class="c"></div>
			</div>
            
        <?php include ("footer.php"); ?>